package cn.gemiman.daoyi.module.cms.controller.admin.appsite.vo;

import cn.gemiman.daoyi.framework.excel.core.annotations.DictFormat;
import cn.gemiman.daoyi.framework.excel.core.convert.DictConvert;
import cn.gemiman.daoyi.module.cms.dal.dataobject.appsite.AppSiteDO;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Schema(description = "管理后台 - 站点 Response VO")
@Data
@ExcelIgnoreUnannotated
public class AppSiteRespVO {

    @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28630")
    @ExcelProperty("编号")
    private Long id;

    @Schema(description = "站点类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @ExcelProperty(value = "站点类型", converter = DictConvert.class)
    @DictFormat("terminal") // TODO 代码优化：建议设置到对应的 DictTypeConstants 枚举类中
    private Integer terminalType;

    @Schema(description = "站点标识", requiredMode = Schema.RequiredMode.REQUIRED, example = "8328")
    @ExcelProperty("站点标识")
    private String appId;

    @Schema(description = "站点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
    @ExcelProperty("站点名称")
    private String appName;

    @Schema(description = "LOGO", example = "https://www.iocoder.cn")
    @ExcelProperty("LOGO")
    private String appLogoUrl;

    @Schema(description = "站点相册")
    @ExcelProperty("站点相册")
    private List<String> appPhotos;

    @Schema(description = "站点简介")
    @ExcelProperty("站点简介")
    private String appShortDesc;

    @Schema(description = "站点介绍", example = "随便")
    @ExcelProperty("站点介绍")
    private String appDescription;

    @Schema(description = "站点配置")
    @ExcelProperty("站点配置")
    private List<AppSiteDO.AppSiteConfigItem> configInfoList;

    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
    @ExcelProperty("创建时间")
    private LocalDateTime createTime;

    @Schema(description = "访问次数")
    @ExcelProperty("访问次数")
    private Long viewTimes;

    @Schema(description = "站点配置")
    public Map<String, Object> getConfigInfoMap() {
        if (null == configInfoList) {
            return MapUtil.newHashMap();
        }
        return configInfoList.stream()
                .map(c -> BeanUtil.copyProperties(c, AppSiteDO.AppSiteConfigItem.class))
                .collect(Collectors.toMap(AppSiteDO.AppSiteConfigItem::getKey, AppSiteDO.AppSiteConfigItem::getValue, (ov, v) -> v));
    }

    @Schema(description = "点赞数量")
    private Long thumbsUpTimes = 0L;

    /**
     * 绑定域名
     */
    @Schema(description = "绑定域名")
    private String bindDomain;
    /**
     * 用户类型
     */
    private Integer userType;
    /**
     * 用户编号
     */
    private Long userId;
    /**
     * 用户昵称
     */
    private String userNickname;
    /**
     * 用户头像
     */
    private String userAvatar;
    /**
     * 评论状态
     * <p>
     * 枚举 {@link TODO common_status 对应的类}
     */
    private Integer status;
    /**
     * 审核状态
     * <p>
     * 枚举 {@link TODO bpm_process_instance_status 对应的类}
     */
    private Integer approveStatus;
}
